//
//  LoginVC.m
//  AKPZ
//
//  Created by Lexi on 16-3-15.
//  Copyright (c) 2016年 aikangpeizhen. All rights reserved.
//

#import "LoginVC.h"
#import "AKRequestManager.h"

@interface LoginVC ()

@property (strong, nonatomic) AKRequestManager *manager;
@property (weak, nonatomic) IBOutlet UITextField *accountField;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UIButton *registBtn;
@property (weak, nonatomic) IBOutlet UIButton *findPwdBtn;

@end

@implementation LoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)initView {
    [self.view viewWithTag:100].hidden = YES;
    [self setLeftBtnHidden:YES];
    [self setRightBtnHidden:YES];
}

#pragma mark - IBAction

- (IBAction)backgroundBtnClicked:(id)sender {
    [_accountField resignFirstResponder];
    [_pwdField resignFirstResponder];
}

- (IBAction)loginBtnClicked:(id)sender {
    NSString *account = _accountField.text;
    NSString *pwd = _pwdField.text;
    if (!account.length) {
        [AKUIToolKit alertMessage:@"请输入账号"];
        return;
    }
    if (![AKToolKit isMobileNumber:account]) {
        [AKUIToolKit alertMessage:@"账号格式错误"];
        return;
    }
    if (!pwd.length) {
        [AKUIToolKit alertMessage:@"请输入密码"];
        return;
    }
    if (![AKToolKit isCorrectPwd:pwd]) {
        [AKUIToolKit alertMessage:@"密码只能为4-16位的数字字母或~!@#$%^&*"];
        return;
    }
    if (pwd.length < 4 || pwd.length > 16) {
        [AKUIToolKit alertMessage:@"密码长度为4-16位"];
        return;
    }
    [_accountField resignFirstResponder];
    [_pwdField resignFirstResponder];
    [self login];
}

- (IBAction)registBtnClicked:(id)sender {
    UIViewController *vc = [StoryBoard(@"LoginAndRegist") instantiateViewControllerWithIdentifier:@"RegistVCSID"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)findPwdBtnClicked:(id)sender {
    UIViewController *vc = [StoryBoard(@"LoginAndRegist") instantiateViewControllerWithIdentifier:@"FindPwdVCSID"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)login {
    NSString *acct = _accountField.text;
    NSString *pwd = _pwdField.text;
    if ([acct isEqualToString:@"13882290321"] && [pwd isEqualToString:@"111111"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:UserLoginNotification object:nil];
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
}

@end
